<template>
  <div class="echarts1" ref="echarts">

  </div>
</template>

<script>
import {FontChart} from '@/utils/utils'
import * as echarts from "echarts"
// import {dmaMonitoring} from "@/api/api/waterSupplyOverview.js";

export default {
  name: 'echarts1',
  components: {},
  props: {
    id: {
      type: String,
      default() {
        return ''
      }
    }
  },
  data() {
    return {
      list: [],
    }
  },
  mounted() {
    var that = this;
    // this.getData();
  },
  methods: {
    async getData() {
      try {
        const res = await dmaMonitoring();
        this.list = res.data;
        this.drawEcharts();
      } catch (err) {
        console.error(err);
      }
    },
    drawEcharts() {
      var that = this
      var data = this.list
      let myChart = echarts.init(this.$refs.echarts)
      window.addEventListener('resize', this.drawEcharts)
      var option = {
        legend: {
          top: 5,
          left: 'center',
          itemWidth: 14,
          itemHeight: 6,
          textStyle: {
            color: 'rgba(255, 255, 255, 1)',
            fontSize: '12'
          },
        },

        grid: {
          top: '50px',
          bottom: '10px',
          left: '20px',
          right: '10px',
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
            shadowStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: 'rgba(220, 239, 238, 0.1)'
              }, {
                offset: 1,
                color: 'rgba(220, 239, 238, 0.5)'
              }], false),
            }
          }
        },
        xAxis: [
          {
            data: data.map(obj => obj.name),
            axisLabel: {
              margin: 10,
              color: 'rgba(143, 173, 204, 1)',
              textStyle: {
                fontSize: 13,
              },
            },
            axisLine: {
              lineStyle: {
                color: '#0a2544',
                width: 1
              }
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: 'rgba(30, 62, 104, 0.66)',
                width: 1,
              }
            },
            axisTick: {
              show: false
            },
          }],
        yAxis: [
          {
            axisLabel: {
              color: 'rgba(143, 173, 204, 1)',
              textStyle: {
                fontSize: FontChart(14),
              },
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: '#0a2544',
              }
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: '#072a7b',
                width: 1,
                type: 'dashed'
              }
            }
          }],
        series: [
          {
            name: '产销差率',
            type: 'bar',
            data: data.map(obj => obj.value),
            smooth: false,
            barWidth: 10,
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0, color: 'rgba(0, 150, 255, 1)' // 顶部颜色
                }, {
                  offset: 1, color: 'rgba(0, 168, 255, 1)' // 底部颜色
                }]),
                barBorderRadius: 2, // 圆角
              },
            },
            label: {
              normal: {
                show: false
              }
            }
          },
          {
            name: '漏损率',
            type: 'bar',
            data: data.map(obj => obj.value2),
            smooth: false,
            barWidth: 10,
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0, color: '#6ac39b' // 顶部颜色
                }, {
                  offset: 1, color: '#6ac39b' // 底部颜色
                }]),
                barBorderRadius: 2, // 圆角
              },
            },
            label: {
              normal: {
                show: false
              }
            }
          },
        ]
      }
      myChart.clear();
      myChart.resize();
      myChart.setOption(option);
    },
  }
}
</script>

<style lang="scss" scoped>
.echarts1 {
  position: relative;
  width: 100%;
  height: 100%;
}
</style>
